/****************************************************************************
 * FILE NAME: 		adc.h
 * 
 * PROJECT NAME: 	EGR330_Project
 * TEAM MEMBERS: 	Kevin Vermeer
 * 					Brandon Ross
 *					Tyler Selk
 *
 *
 * CREATED: 		31 July 2011 (Brandon Ross)
 * LAST MODIFIED: 		
 * 
 * DESCRIPTION:		Handles functions necessary to operate ADC peripheral
 ****************************************************************************/

/* HEADER GUARD */
#ifndef ADC_H
#define ADC_H

/***** DEFINITIONS *****/

/* Definitions of ADC Masks */
#define ADC_MASK_MUXX 0x0F
#define ADC_MASK_REFSX 0xC0
#define ADC_MASK_ADPSX 0x07
#define ADC_MASK_ADCXD 0x3F
#define ADC_MASK_ADTSX 0x07

/* Shift Positions of ADC_MASK within register */
#define ADC_POS_MUXX 0
#define ADC_POS_REFSX 6
#define ADC_POS_ADPSX 0
#define ADC_POS_ADCXD 0
#define ADC_POS_ADTSX 0

/* Definitions of ADC Voltage Reference Sources */
#define ADC_VREF_AREF 0x00
#define ADC_VREF_AVCC 0x01
#define ADC_VREF_INTERNAL 0x03

/* Definitions of ADC Prescale Division Factors */
#define ADC_PRESCALE_DF2 0x00
#define ADC_PRESCALE_DF4 0x02
#define ADC_PRESCALE_DF8 0x03
#define ADC_PRESCALE_DF16 0x04
#define ADC_PRESCALE_DF32 0x05
#define ADC_PRESCALE_DF64 0x06
#define ADC_PRESCALE_DF128 0x07

/* Definitions of ADC Auto Trigger Sources */
#define ADC_AUTOTRIG_FREERUN 0x00
#define ADC_AUTOTRIG_ANACOMP 0x01
#define ADC_AUTOTRIG_EIR0 0x02
#define ADC_AUTOTRIG_T0CMA 0x03
#define ADC_AUTOTRIG_T0OF 0x04
#define ADC_AUTOTRIG_T1CMB 0x05
#define ADC_AUTOTRIG_T1OF 0x06
#define ADC_AUTOTRIG_T1CE 0x07

#define ADC_INPUTS_ALL 0x3F

#define ADC_BIT_ENABLE 0x80
#define ADC_BIT_START 0x40
#define ADC_BIT_DONE 0x10
#define ADC_BIT_ADLAR 0x20

/***** TYPE DEFINITIONS *****/

typedef volatile uint16_t adc_reading_t;

/***** FUNCTION PROTOTYPES *****/

void ADC_initialize(void);

adc_reading_t readCurrent(uint8_t CURRX);

#endif
